home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: iiasa.ac.at!marek
- From: marek@iiasa.ac.at (Marek MAKOWSKI)
- Subject: Re: error: undef. but decl. template as member
- Message-ID: <1996Mar16.085325.25956@iiasa.ac.at>
- Organization: IIASA, Laxenburg, Austria
- X-Newsreader: TIN [version 1.2 PL2]
- References: <Do6owF.LKo@news.uwindsor.ca>
- Date: Sat, 16 Mar 1996 08:53:25 GMT
-
- Saed Aryan,13325,1100,g (saed@engn.uwindsor.ca) wrote:
- : Hi all,
-
- : I am curious to know:
-
- : --- Why is it not sufficient to declare a template in order to be able to
- : use it as a member of a class, and then to define the template class later.
-
- : I would like to know whether this is compiler specific or whether it's a C++
- : template flaw, since the error does not make logical sense to me.
- : The code snippet below shows the problem. If you succeed in compiling this code
- : errorless, or if you have an explanataion, I'd be glad to know!
-
- : Thanks a lot,
- : Aryan.
-
- : //----cut here
- : template <class T> class A1{}; // A1 declared and defined
- : template <class T> class A2; // A2 just declared
-
- : class B1 {private: A1<int> a1;};// okay, A1 with template is defined
- // and therefore size of A1<int> is known at this point.
- : class B2 {private: A2<int> a2;};// error: field `a2' has incomplete type
- // size of A2<int> is unknown at this point.
- // If there is a reason (often it is) to keep it uknown then you can use:
- class B2 {private: A2<int> *a2;};// should be OK
-
- Good luck,
- Marek
-
-
- --
- Marek Makowski | Email: marek@iiasa.ac.at
- International Institute | Phone: (+43-2236) 807.561
- for Applied Systems Analysis | Fax: (+43-2236) 71.313
- A-2361 Laxenburg, Austria | Web: http://www.iiasa.ac.at
-